<?php

namespace Crm\Model;

/**
 * GeneralRegionModel数据库模型
 *
 * @author SoChishun <14507247@qq.com>
 * @version 1.0
 * @since 1.0.0 <2015-3-24> by SoChishun Added.
 */
class CommonRegionModel extends AppbaseModel {

    /**
     * 数据表名称
     * @var string
     */
    protected $tableName = 'tcommon_region';

    /**
     * 字段定义
     * @var array
     */
    protected $fields = array();

    /**
     * 命名范围
     * @var array
     */
    protected $_scope = array();

    /**
     * 是否批量验证
     * @var boolean
     */
    protected $patchValidate = true;

    /**
     * 验证规则
     * @var array
     */
    protected $_validate = array();

    /**
     * 自动填充
     * @var array
     */
    protected $_auto = array();

    public function get_list($province, $city) {
        if ($province) {
            $parent = $this->where("regionName='$province' and parentID=0")->getField('id');
            if ($city) {
                $parent = $this->where("regionName='$city' and parentID=$parent")->getField('id');
            }
        } else {
            $parent = 0;
        }
        $key = 'region' . $parent;
        $list = F($key);
        if (!$list) {
            $list = $this->where('parentID=' . $parent)->getField('regionName', true);
            F($key,$list);
        }
        return $list;
    }

}
